/*
 * Copyright 2008 FBK (http://www.fbk.eu/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fbk.it.hlt.jlsi;

import org.apache.log4j.Logger;

import cern.colt.matrix.DoubleMatrix1D;

/**
 * An abstract implementation of the term symilarity.
 * 
 * @author Claudio Giuliano
 * @version %I%, %G%
 * @since 1.0
 * @see AbstractTermSimilarity
 */
public abstract class AbstractTermSimilarity implements TermSimilarity {
	/**
	 * Define a static logger variable so that it references the Logger instance
	 * named <code>AbstractTermSimilarity</code>.
	 */
	static Logger logger = Logger.getLogger(AbstractTermSimilarity.class
			.getName());

	//
	double cosine(DoubleMatrix1D x1, DoubleMatrix1D x2) {
		double d1 = x1.zDotProduct(x1);
		double d2 = x2.zDotProduct(x2);

		// logger.debug(d1 + " * " + d2 + " = " + x1.zDotProduct(x2) + " / " +
		// Math.sqrt(d1 * d2));
		return x1.zDotProduct(x2) / Math.sqrt(d1 * d2);
	} // end dot

} // end class AbstractTermSimilarity